/*
 * Modified sample code from mgwt showcase
 * Copyright 2010 Daniel Kurka
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package de.dhbw.vs.permachat.client.activities.login;

import com.google.gwt.event.dom.client.HasKeyUpHandlers;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.mgwt.dom.client.event.tap.HasTapHandlers;
import com.googlecode.mgwt.ui.client.MGWTStyle;
import com.googlecode.mgwt.ui.client.widget.Button;
import com.googlecode.mgwt.ui.client.widget.HeaderPanel;
import com.googlecode.mgwt.ui.client.widget.LayoutPanel;
import com.googlecode.mgwt.ui.client.widget.MTextBox;
import com.googlecode.mgwt.ui.client.widget.WidgetList;

/**
 * @author flo
 * 
 */
public class LoginViewGwtImpl implements LoginView {
	
	private LayoutPanel main;
	private HeaderPanel headerPanel;
	private Button loginButton;
	private MTextBox userNameTextBox;

	/**
	 * 
	 */
	public LoginViewGwtImpl() {
		main = new LayoutPanel();

		headerPanel = new HeaderPanel();
		main.add(headerPanel);
		
		HTML header = new HTML("Login");
	    header.addStyleName(MGWTStyle.getTheme().getMGWTClientBundle().getListCss().listHeader());
		
		userNameTextBox = new MTextBox();
		userNameTextBox.setPlaceHolder("Type your name...");
		
		loginButton = new Button("Go");
		loginButton.setConfirm(true);

		WidgetList widgetList = new WidgetList();
		widgetList.setRound(true);
		widgetList.add(new Label("Name:"));
		widgetList.add(userNameTextBox);
		widgetList.add(loginButton);
		
		main.add(header);
		main.add(widgetList);

	}

	@Override
	public Widget asWidget() {
		return main;
	}

	@Override
	public void setTitle(String text) {
		headerPanel.setCenter(text);
	}
	
	@Override
	public HasText getUserNameField() {
		return this.userNameTextBox;
	}
	
	@Override
	public HasTapHandlers getLoginButton() {
		return this.loginButton;
	}

	@Override
	public HasKeyUpHandlers getUserNameFieldSender() {
		return this.userNameTextBox;
	}

	@Override
	public void focusUserNameField() {
		this.userNameTextBox.setFocus(true);
		this.userNameTextBox.getElement().focus();
	}

}
